class Order < ActiveRecord::Base
  belongs_to :user
  belongs_to :address
  has_many   :line_items

  PAYTYPE = [
    [ "货到付款",   1 ],
    [ "支付宝",   2 ]
  ]

  SHIPPING_TYPE = [
    [ "快递",   1 ],
    [ "邮政",   2 ],
    [ "自取",   3 ]
  ]

  STATUS = [

    [ "待确认",   1 ],
    [ "配货中",   2 ],
    [ "已发货",   3 ],
    [ "已取消",   4 ]

  ]

  def add_line_items_from_cart(cart)
    cart.items.each do |item|
      li = LineItem.from_cart_item(item)
      line_items << li
    end
  end

  def real_total_price
    line_items.inject(0) { |sum,item| sum+item.real_total_price }
  end

  def display_total_price
    line_items.inject(0) { |sum,item| sum+item.display_total_price }
  end
end
